#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
using namespace std;
int n;
int a[100001];
ll f[100001];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        f[i]=a[i];
        for(int j=i-1;j>=1;j--){
            if(a[j]>=a[i]){
                f[i]+=a[j];
            }
            else{
                break;
            }
        }
        for(int j=i+1;j<=n;j++){
            if(a[j]>=a[i]){
                f[i]+=a[j];
            }
            else{
                break;
            }
        }
        f[i]=f[i]*a[i];
        ans=max(ans,f[i]);
    }
    printf("%lld",ans);
    return 0;
}


SYNTAXTREE* factor() {
	if (curtoken == LPARENT) {
		match(LPARENT);
		SYNTAXTREE* node = expression();
		match(RPARENT);
		return node;
	} //如果是括号表达式
	else if (curtoken == VALUE) {
		SYNTAXTREE* node = newExpnode(CONSTK);
		node->val = atoi(getTokenname());
		match(VALUE);
		return node;
	} //如果是常量
	else if (curtoken == ID) {
		SYNTAXTREE* name = newExpnode(IDK);
		strcpy(name->name, getTokenname());
		match(ID);
		if (curtoken == LPARENT) {
			match(LPARENT);
			SYNTAXTREE* node = newStatenode(CALLK);
			node->children[0] = name;
			if (curtoken == RPARENT) {
				match(RPARENT);
				return node;
			}
			name->sibling = args();
			match(RPARENT);
			return node;
		} //如果是函数调用
		else if (curtoken == LBRACKET) { 
			match(LBRACKET);
			SYNTAXTREE* node = newStatenode(ARRY_ELEMK);
			node->children[0] = name;
			name->sibling = expression();
			match(RBRACKET);
			return node;
		}//如果是数组
		else {
			return name;
		}
	}
	else {
		SYNTAXTREE* err = sytanxerr(getTokenname());
		curtoken = getToken();
		return err;
	}
}

